﻿package commands 
{
	import flash.utils.ByteArray;	
	import commands.classesinfo.*;
	/**
	 * ...
	 * @author wwx
	 * 30000006 进入桌子(返回)
	 */
	public class EnterDeskCmdRsp extends abCommand  
	{
		
		public function EnterDeskCmdRsp() //: abCommand(CommandType.CMD_TYPE_ENTERDESK_RSP)  
		{
			super(CommandType(CommandType.CMD_TYPE_ENTERDESK_RSP));
			errorNum = -1;
			deskId = -1;
			gameStatus = 0;
			publicCardsInfo = new Array();
			playerCount = 0;
			playersInfo = new Array();
		}
/*		
		public var msgSeq:int;//消息号
		public var errorNum:int;//错误号
		
		public var deskId:int;//桌子id
		public var deskPosition:int;//桌子位置
		
		public var hadChip:int;//拥有的筹码;
		public var minChip:int;//最低带入筹码;
		public var maxChip:int;//最高带入筹码;
		
		public var playerCount:int;//房间中，玩家的人数。
		public var playersInfo:Array;//PlayerInfoInDesk
		
		public function convertToCmd(bytes:ByteArray, offset:int, len:int):int
		{
			var ret:int = -1;
			msgSeq = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8) + ((int(bytes[offset + 2])) << 16) + ((int(bytes[offset + 3])) << 24);
			offset += 4;
			errorNum = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
			offset += 4;
			
			deskId = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
			offset += 4;
			deskPosition = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
			offset += 4;
			hadChip = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
			offset += 4;	
			minChip = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
			offset += 4;	
			maxChip = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
			offset += 4;		
			
			playerCount = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
			offset += 4;				
			
			playersInfo = new Array();
			var playerInfo:PlayerInfoInDesk = null;
			var stringLen:int = 0;
			for (var i:int = 0; i < playerCount; i++)
			{
				playerInfo = new PlayerInfoInDesk();
				playerInfo.id = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8) + ((int(bytes[offset + 2])) << 16) + ((int(bytes[offset + 3])) << 24);
				offset += 4;
				
				stringLen = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8);
				offset += 2;
				
				bytes.position = offset;
				playerInfo.name = bytes.readMultiByte(stringLen,"gb2312");
				offset += stringLen;
				
				playerInfo.status = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8) + ((int(bytes[offset + 2])) << 16) + ((int(bytes[offset + 3])) << 24);
				offset += 4;

				playersInfo[i] = playerInfo;
			}
			return 0;
		}			
*/		
		
		public var msgSeq:int;//消息号
		public var errorNum:int;//错误号
		
		public var deskId:int;//桌子id
		public var gameStatus:int;//游戏状态,0：未开始,1：已开始

		public var publicCardsInfo:Array;//CardInfo,游戏已开始才有该字段,公共牌信息
		
		public var playerCount:int;//房间中，玩家的人数。
		public var playersInfo:Array;//PlayerInfoInDesk
		
		public function convertToCmd(bytes:ByteArray, offset:int, len:int):int
		{
			var ret:int = -1;
			msgSeq = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8) + ((int(bytes[offset + 2])) << 16) + ((int(bytes[offset + 3])) << 24);
			offset += 4;
			errorNum = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
			offset += 4;
			
			deskId = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
			offset += 4;
			gameStatus = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
			offset += 4;
			
			var i:int = 0;		
			var cardInfo:CardInfo = null;
			if (1 == gameStatus)
			{			
				ret = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
				offset += 4;	

				//publicCardsInfo = new Array();				
				for (i = 0; i < ret; i++)
				{
					cardInfo = new CardInfo();
					cardInfo.colorOfCard = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
					offset += 4;
					cardInfo.contentOfCard = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
					offset += 4;
					
					publicCardsInfo[i] = cardInfo;
				}
			}
			
			playerCount = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
			offset += 4;
			
			var playerInfoInDesk:PlayerInfoInDesk = null;
			//playersInfo = new Array();
			for (i = 0; i < playerCount; i++)
			{
				playerInfoInDesk = new PlayerInfoInDesk();
				playerInfoInDesk.seatId = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
				offset += 4;
				playerInfoInDesk.playerId = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
				offset += 4; 
				if (0 != playerInfoInDesk.playerId)
				{
					ret = (int) (bytes[offset + 0]) + ((int(bytes[offset + 1])) << 8);
					offset += 2;
					bytes.position = offset;
					playerInfoInDesk.name = bytes.readMultiByte(ret, "gb2312");
					offset += ret;
					
					playerInfoInDesk.status = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
					offset += 4; 
					
					playerInfoInDesk.curChipsOfPlayer = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
					offset += 4; 
					
					playerInfoInDesk.curInject = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
					offset += 4; 
					
					//playerInfoInDesk.cardInfo = new Array();
					
					if (2 == playerInfoInDesk.status || 3 == playerInfoInDesk.status)
					{
						playerInfoInDesk.isShow = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
						offset += 4; 
									
						cardInfo = new CardInfo();
						cardInfo.colorOfCard = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
						offset += 4; 
						cardInfo.contentOfCard = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
						offset += 4; 
						playerInfoInDesk.cardInfo[0] = cardInfo;
						cardInfo = new CardInfo();
						cardInfo.colorOfCard = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
						offset += 4; 
						cardInfo.contentOfCard = (int) (bytes[offset + 0]) + ((int(bytes[offset+1])) << 8) + ((int(bytes[offset+2])) << 16) + ((int(bytes[offset+3])) << 24);
						offset += 4; 
						playerInfoInDesk.cardInfo[1] = cardInfo;
					}
				}
				playersInfo[i] = playerInfoInDesk;
			}
			
			return 0;
		}	
	}
	
}